package org.wlldTest.FileDemo;

import org.wlld.entity.KeyWordForSentence;
import org.wlld.naturalLanguage.languageCreator.CatchKeyWord;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class Test {
    public static List<CatchKeyWord> catchKeyWordList = new ArrayList<>();

    public static Docment go(List<Docment> docments, String a) throws Exception {
        List<KeyWordForSentence> urls = new ArrayList<>();
        List<KeyWordForSentence> parameterNames = new ArrayList<>();
        List<KeyWordForSentence> parameterValues = new ArrayList<>();
        for (Docment myWord : docments) {
            KeyWordForSentence url = new KeyWordForSentence();
            KeyWordForSentence parameterName = new KeyWordForSentence();
            KeyWordForSentence parameterValue = new KeyWordForSentence();
            url.setSentence(myWord.getSentence());
            url.setKeyWord(myWord.getUrl());
            parameterName.setSentence(myWord.getSentence());
            parameterName.setKeyWord(myWord.getParameterName());
            parameterValue.setSentence(myWord.getSentence());
            parameterValue.setKeyWord(myWord.getParameterValue());
            urls.add(url);
            parameterNames.add(parameterName);
            parameterValues.add(parameterValue);
        }
        catchKeyWordList.get(0).study(urls);
        catchKeyWordList.get(1).study(parameterNames);
        catchKeyWordList.get(2).study(parameterValues);
        Set<String> urlSet = catchKeyWordList.get(0).getKeyWord(a);
        Set<String> nameSet = catchKeyWordList.get(1).getKeyWord(a);
        Set<String> valueSet = catchKeyWordList.get(2).getKeyWord(a);
        Docment docment = new Docment();
        docment.setUrl(new ArrayList<>(urlSet).get(0));
        docment.setParameterName(new ArrayList<>(nameSet).get(0));
        docment.setParameterValue(new ArrayList<>(valueSet).get(0));
        return docment;
    }

    public static void main(String[] args) throws Exception {
        init();
        Docment docment = go(data(), "接口https://www.adwwdd.com，参数名tre值为：1d3");
        System.out.println("请求URL：" + docment.getUrl());
        System.out.println("参数名称：" + docment.getParameterName());
        System.out.println("参数值：" + docment.getParameterValue());
    }

    public static void init() {
        for (int i = 0; i < 3; i++) {
            CatchKeyWord catchKeyWord = new CatchKeyWord();
            catchKeyWord.setProTh(-10);
            catchKeyWordList.add(catchKeyWord);
        }
    }

    public static List<Docment> data() {
        List<Docment> docments = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            Docment docment = new Docment();
            if (i == 0) {
                docment.setSentence("请求地址$，参数&值为：#");
                docment.setUrl("$");
                docment.setParameterName("&");
                docment.setParameterValue("#");
            } else if (i == 1) {
                docment.setSentence("接口$，参数名&值为：#");
                docment.setUrl("$");
                docment.setParameterName("&");
                docment.setParameterValue("#");
            } else {
                docment.setSentence("接口地址$，参数名称&值为：#");
                docment.setUrl("$");
                docment.setParameterName("&");
                docment.setParameterValue("#");
            }
            docments.add(docment);
        }
        return docments;
    }
}
